<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>评论修改</legend>
</fieldset>
<form class="layui-form" action="" >
    <div class="layui-form-item">
        <label class="layui-form-label">评论编号</label>
        <div class="layui-input-block">
            <input type="text" name="id" disabled="disabled" autocomplete="off" class="layui-input" th:value="${comment.getId()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评论内容</label>
        <div class="layui-input-block">
            <input type="text" name="content" lay-verify="required" autocomplete="off" class="layui-input" th:value="${comment.getContent()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评分</label>
        <div class="layui-input-block">
            <input type="hidden" th:value="${comment.getScore()}" id="sc">
            <div id="score" name="score" class="demo-slider"></div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="update1">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'slider'], function (){
        var form = layui.form, $ = layui.jquery,
            slider = layui.slider;
        var score = document.getElementById('sc').value;
        form.on('submit(update1)', function (data) {
            data = data.field;
            data["score"] = score;
            $.ajax({
                url:"/updateBorrowerComment",
                type:"POST",
                data:data,
                success:function (result){
                    if (result.code==200){
                        layer.msg("修改成功",{
                            icon:6,
                            time:500
                        });
                    }else {layer.msg(result.msg);}
                }
            });
            return false;
        });
        slider.render({
            elem: '#score',
            value: document.getElementById('sc').value,
            input: true,
            change: function(value){
                console.log(value) //动态获取滑块数值
                //do something
                score = value;
            }
        });
        form.verify({
            password:function (value, item){
                if(!/[0-9a-zA-Z]{6,9}/.test(value)){
                    return "密码格式错误";
                }
            },
        })
    })
</script>
</body>
</html>